import { Component, Injector, ViewChild } from '@angular/core';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { MessageService } from '@abp/message/message.service';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { InspectionHandleServiceProxy, InspectionFileCommonServiceServiceProxy, InspectionSeverityDescOutDto, InspectionStandardDescDto, CodeFormatDescServiceProxy, OperationHistoryServiceProxy, InspectionTypeDescDto, InspectionFileUploadDto } from '@shared/service-proxies/service-proxies';
import { finalize } from 'rxjs/operators';
import { AppComponentBase } from '@shared/common/app-component-base';
import { AppSessionService } from '@shared/common/session/app-session.service';


@Component({
  selector: 'app-exception-report',
  templateUrl: './exception-report.component.html',
  styleUrls: ['./exception-report.component.less']
})
export class ExceptionReportComponent extends AppComponentBase {
  @ViewChild('paginator') paginator: Paginator;
  @ViewChild('dataTable') dataTable: Table;



  constructor(
    injector: Injector,
    private _messageService: MessageService,
    private _inspectionHandleServiceProxy: InspectionHandleServiceProxy,
    private _codeFormatDescServiceProxy: CodeFormatDescServiceProxy,
    private _operationHistoryServiceProxy: OperationHistoryServiceProxy,
    private _inspectionFileCommonServiceServiceProxy: InspectionFileCommonServiceServiceProxy,
    private _user: AppSessionService,



  ) {
    super(injector);
    this.data = {
      labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
      datasets: [
        {
          label: 'My First dataset',
          backgroundColor: '#42A5F5',
          borderColor: '#1E88E5',
          data: [65, 59, 80, 81, 56, 55, 40]
        },
        {
          label: 'My Second dataset',
          backgroundColor: '#9CCC65',
          borderColor: '#7CB342',
          data: [28, 48, 40, 19, 86, 27, 90]
        }
      ]
    };
    this.data2 = {
      labels: ['A', 'B', 'C'],
      datasets: [
        {
          data: [300, 50, 100],
          backgroundColor: [
            "#FF6384",
            "#36A2EB",
            "#FFCE56"
          ],
          hoverBackgroundColor: [
            "#FF6384",
            "#36A2EB",
            "#FFCE56"
          ]
        }]
    };
  }

  tasklist: any = [];//任务编号列表
  queryInfo = {
    taskCode: undefined,//任务编号
    inspectionTypeDescId: undefined,//一级异常id
    inspectionItemInfoId: undefined,//二级异常id
    inspectionSeverityDescId: undefined,//异常等级id
    submitterId: undefined,//提报人id
    handlerId: undefined,//处理人id
    userId: this._user.userId,//查看人id 
  };//查询条件
  typeDescList: any[];//一级异常下拉
  rangeDates: string;//统计时间
  data: any;
  data2: any;


  ngOnInit() {

  }
  //异常列表
  getDescList(event?: LazyLoadEvent): void {
    if (this.primengTableHelper.shouldResetPaging(event)) {
      this.paginator.changePage(0);
      return;
    }

    this._inspectionHandleServiceProxy.getInspectionStandardDescList(
      this.queryInfo.taskCode,
      this.queryInfo.inspectionTypeDescId ? this.queryInfo.inspectionTypeDescId.id : undefined,
      this.queryInfo.inspectionItemInfoId ? this.queryInfo.inspectionItemInfoId.id : undefined,
      this.queryInfo.inspectionSeverityDescId ? this.queryInfo.inspectionSeverityDescId.id : undefined,
      this.queryInfo.submitterId ? this.queryInfo.submitterId.id : undefined,
      this.queryInfo.handlerId ? this.queryInfo.handlerId.id : undefined,
      this.queryInfo.userId ? this.queryInfo.userId : undefined,
      this.primengTableHelper.getSorting(this.dataTable),//undefined
      this.primengTableHelper.getMaxResultCount(this.paginator, event),//10
      this.primengTableHelper.getSkipCount(this.paginator, event)//0
    )
      .pipe(finalize(() => { }))
      .subscribe(result => {
        this.primengTableHelper.totalRecordsCount = result.totalCount;
        this.primengTableHelper.records = result.items;
        this.primengTableHelper.hideLoadingIndicator();

      });
  }






  //任务编号下拉列表
  getTaskList(): void {
    this._inspectionHandleServiceProxy.getCodeTaskList(undefined)
      .pipe(finalize(() => { }))
      .subscribe(result => {
        let taskList: any = result
        taskList.forEach(element => {
          let taskItem = {
            value: element,
            label: element
          }
          this.tasklist.push(taskItem)
        });
        //  this.primengTableHelper.totalRecordsCount = result.totalCount;
        //  this.primengTableHelper.records = result.items;
        //  this.primengTableHelper.hideLoadingIndicator();
      });
  }
  //一级异常 下拉列表
  gettypeDescList(): void {
    this._inspectionHandleServiceProxy.getInspectionTypeDescList(
      undefined
    )
      .pipe(finalize(() => { }))
      .subscribe(result => {
        this.typeDescList = result
      });
  }





}
